import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'
import router from './router'
import store from './store'
//import './plugins/element.js'
import VueRouter from 'vue-router'



Vue.use(ElementUI);
Vue.use(VueRouter)


Vue.config.productionTip = false



router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
    if(to.path == '/login'){
      sessionStorage.removeItem('user');
    }
    let user = JSON.parse(sessionStorage.getItem('user'));
    if(!user && to.path!='/login'){   //如果sessionStorage里面的用户名为空，且即将进入的路由对象不是登录路由
      next({path:'/login'})
    }
    else{
      next();
    }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
